package com.yenlien.traceyun.business.service.rest.control;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.bean.RestURL;
import com.yenlien.traceyun.business.service.rest.RestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * Created by LiuSha on 2020/9/17.
 */
@Service
public class ModelCropRestService {
    @Autowired
    private RestService restService;


    /**
     * 添加
     *
     * @param map
     * @param files
     * @param companyId
     * @return
     */
    public Object add(Map<String, Object> map, List<MultipartFile> files, String companyId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = new String("");
        }
        return restService.postForm(RestURL.CONTROL + "model/crop/add?companyId=" + companyId, map, files);
    }

    /**
     * 根据分类加载所有作物
     *
     * @param categoryId
     * @return
     */
    public Object loadByCategoryId(String categoryId) {
        return restService.getJson(RestURL.CONTROL + "model/crop/category/" + categoryId);
    }

    /**
     * 根据id加载所有作物
     *
     * @param id
     * @return
     */
    public Object load(String id) {
        return restService.getJson(RestURL.CONTROL + "model/crop/load/" + id);
    }

    /**
     * 绑定解绑作物
     *
     * @param params
     * @return
     */
    public Object bindone(JSONObject params) {
        return restService.postJson(RestURL.CONTROL + "model/crop/bindone/", params);
    }

    /**
     * 加载加载产出物
     *
     * @param modelId
     * @return
     */
    public Object loadCrop(String modelId) {
        return restService.getJson(RestURL.CONTROL + "model/crop/load/crop/" + modelId);
    }

    /**
     * 添加作物
     *
     * @param params
     * @return
     */
    public Object addCrop(JSONObject params) {
        return restService.postJson(RestURL.CONTROL + "model/crop/add/crop", params);
    }

    /**
     * 根据公司绑定
     *
     * @param jsonObject
     * @return
     */
    public Object findByCompany(JSONObject jsonObject) {
        return restService.postJson(RestURL.CONTROL + "model/crop/loadbind", jsonObject);
    }

    /**
     * 查询
     *
     * @param jsonObject
     * @return
     */
    public Object search(JSONObject jsonObject) {
        return restService.postJson(RestURL.CONTROL + "model/crop/search", jsonObject);
    }

    /**
     * ------------------------------------------------
     **/

    public Object findByModelId(String modelId) {
        return restService.getJson(RestURL.CONTROL + "model/crop/findByModelId/" + modelId);
    }


    public Object save(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.CONTROL + "model/crop/save", map, files);
    }

    public Object update(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.CONTROL + "model/crop/update", map, files);
    }

    public Object findById(String id) {
        return restService.getJson(RestURL.CONTROL + "model/crop/findById/" + id);
    }

    public Object findByOneId(String id) {
        return restService.getJson(RestURL.CONTROL + "model/crop/findByOneId/" + id);
    }

    public Object findByTwoId(String id) {
        return restService.getJson(RestURL.CONTROL + "model/crop/findByTwoId/" + id);
    }


    public Object saveCompanyModel(JSONObject jsonObject) {
        return restService.postJson(RestURL.CONTROL + "model/crop/company/save", jsonObject);
    }

    public Object deleteCompanyModel(JSONObject jsonObject) {
        return restService.postJson(RestURL.CONTROL + "model/crop/company/delete", jsonObject);
    }
}
